package com.sdleyou.treepro.business.api.order;

import com.sdleyou.treepro.common.model.utils.ResultVOUtil;
import com.sdleyou.treepro.common.model.vo.ResultVO;
import com.sdleyou.treepro.common.service.OrderManager;
import com.sdleyou.treepro.common.service.UserFriendManager;
import com.sdleyou.treepro.system.version.ApiVersion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
public class OrderController {

    @Autowired
    private OrderManager userFriendManager;

    /**
     * 订单列表
     */
    @ApiVersion(1)
    @PostMapping("/{version}/order/list")
    public ResultVO orderList(@RequestParam("user_id") String userId,
                              @RequestParam(name = "page_size", defaultValue = "10") Integer pageSize,
                              @RequestParam(name = "page_num", defaultValue = "1") Integer pageNum,
                              Integer orderStatus) {
        return ResultVOUtil.success(userFriendManager.getOrderList(userId, orderStatus, pageNum, pageSize));
    }

    /**
     * 生成订单
     */
    @ApiVersion(1)
    @PostMapping("/{version}/order/add")
    public ResultVO addOrder(@RequestParam("user_id") String userId,
                              @RequestParam("tree_id") String treeId,
                              @RequestParam("num") Integer num) {
        return ResultVOUtil.success(userFriendManager.addOrder(userId, treeId, num));
    }
}
